package com.shop.shoppingmall.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import net.sf.json.JSONArray;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * (ShHistory)实体类
 *
 * @author makejava
 * @since 2020-09-10 15:20:00
 */
@Data
public class ShHistory implements Serializable {
    private static final long serialVersionUID = -55599802790969288L;
    /**
     * 主键
     */
    private String id;
    /**
     * 用户id
     */
    private String userId;
    /**
     * 商品id
     */
    private String productId;
    private String times;
    private String productName;
    private  String productSpecs;
    private  String photo;
    private BigDecimal productPrice;
    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8")
    private Date creatTime;
    /**
     * 更新时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8")
    private Date updateTime;

    private String flag;


    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getProductId() {
        return productId;
    }

    public void setProductId(String productId) {
        this.productId = productId;
    }

    public Date getCreatTime() {
        return creatTime;
    }

    public void setCreatTime(Date creatTime) {
        this.creatTime = creatTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public String getFlag() {
        if("".equals(flag)||flag==null){
            return "1";//去除该属性的前后空格并进行非空非null判断
        }
        return flag;
    }

    public void setFlag(String flag) {
        this.flag = flag == null ? null : flag.trim();
    }
    /*规格处理*/
    public String getProductSpecs() {
        List<String> list = new ArrayList<String>();
        JSONArray jsonArray = JSONArray.fromObject(productSpecs);//把String转换为json
        list = JSONArray.toList(jsonArray);//这里的t是Class<T>
        String str = list.toString().replaceAll("(?:\\[|null|\\]| +)", "");
        return str;
    }

}